package com.neptune.imapp.repository.module

import android.content.Context
import androidx.room.Room
import com.google.gson.Gson
import com.neptune.imapp.repository.IMDataBase
import com.neptune.imapp.repository.mapper.HistoryMapper
import com.neptune.imapp.repository.service.UserService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

@Module
@InstallIn(SingletonComponent::class)
object AppModule {

    @Provides
    fun provideDataBase(@ApplicationContext context: Context): IMDataBase {
        return Room.databaseBuilder(context, IMDataBase::class.java, "IM").build()
    }

    @Provides
    fun provideHistoryMapper(database: IMDataBase): HistoryMapper {
        return database.historyMapper();
    }

    @Provides
    fun provideRetrofit(): Retrofit {
        return Retrofit.Builder().baseUrl("http://192.168.1.3:10010")
            .addConverterFactory(GsonConverterFactory.create(Gson()))
            .build()
    }

    @Provides
    fun provideUserService(retrofit: Retrofit): UserService {
        return retrofit.create(UserService::class.java)
    }

    @Provides
    fun provideGson(): Gson {
        return Gson()
    }
}